//
//  XMLProductInformationShow.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/6.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XMLProductInformationShowModelArray.h"
#import "XXTool.h"

@implementation XMLProductInformationShowModel

@end

@implementation XMLProductInformationShowModelArray

+(instancetype)modelWithDictionary:(NSDictionary *)dict
{
    XMLProductInformationShowModelArray *model = [super modelWithDictionary:dict];
    NSMutableArray *productList = [[NSMutableArray alloc] init];
    if ([[dict objectForKey:@"total"] intValue]==0)
    {
        model.list = [NSMutableArray array];
        return model;
    }
    for (NSDictionary *temp in [dict objectForKey:@"list"])
    {
        [productList addObject:[XMLProductInformationShowModel modelWithDictionary:temp]];
    }
    model.list = productList;
    return model;
}

+(void)sendRequestToGetProductInformationShowListWithListCount:(NSInteger)count  completion:(void (^)(BOOL, XMLProductInformationShowModelArray *))completion
{
    [DKHTTPRequest sendDataWithShortUrl:@"commerce_trade_goodslist"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&nstart=%ld&ntotal=10",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,(long)count]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     if (completion)
                                     {
                                         completion(YES,[XMLProductInformationShowModelArray modelWithDictionary:serverDic]);
                                     }
                                 }
                                 else
                                 {
                                     if (completion)
                                     {
                                         completion(NO,nil);
                                     }
                                     
                                 }
                                 return YES;
                             } IsBuffering:YES IsNeedReplaceWrap:YES
     IsUseUpLoadHead:NO];
}

+(void)requestProductCollectListWithListCount:(NSInteger)count completion:(void (^)(BOOL, NSMutableArray<XMLProductInformationShowModel *> *))block
{
    [DKHTTPRequest sendDataWithShortUrl:@"favorites_goods"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&nstart=%ld&ntotal=10",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,count]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     NSMutableArray *list = [NSMutableArray array];
                                     if ([[serverDic objectForKey:@"total"] intValue]!=0)
                                     {
                                         NSArray *tempArray = [serverDic objectForKey:@"exlist"];
                                         for (NSDictionary * temp in tempArray)
                                         {
                                             [list addObject:[XMLProductInformationShowModel modelWithDictionary:temp]];
                                         }
                                     }
                                     block(YES,list);
                                 }
                                 else
                                 {
                                     block(NO,nil);
                                    
                                 }
                                 return YES;
                             } IsBuffering:YES
                      IsNeedReplaceWrap:YES
                        IsUseUpLoadHead:NO];
}

+(void)requestProuductSearchResultsListWithSearchKey:(NSString *)key searchType:(NSString *)type Count:(NSInteger)count completion:(void (^)(BOOL, NSMutableArray<XMLProductInformationShowModel *> *))block
{
    [DKHTTPRequest sendDataWithShortUrl:@"commerce_trade_goodssearch"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&nstart=%ld&ntotal=10&searchkey=%@&searchtype=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,count,key,type]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     NSMutableArray <XMLProductInformationShowModel*> *list = [NSMutableArray array];
                                     if ([[serverDic objectForKey:@"total"] intValue]!=0)
                                     {
                                         NSArray *tempArray = [serverDic objectForKey:@"list"];
                                         for (NSDictionary *temp in tempArray)
                                         {
                                             [list addObject:[XMLProductInformationShowModel modelWithDictionary:temp]];
                                         }
                                     }
                                     block(YES,list);
                                 }
                                 else
                                 {
                                     block(NO,nil);
      
                                 }
                                 return YES;
                             } IsBuffering:NO
                      IsNeedReplaceWrap:NO
                        IsUseUpLoadHead:NO];
}

@end
